package com.example.download2;

import java.util.Random;

import android.annotation.TargetApi;
import android.app.Activity;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends Activity {

	DownloadByAppacheHttp d;
    @TargetApi(9)
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        final String link="http://tudien-idict.googlecode.com/files/vietviet.db";
        //link="http://mgame.soha.vn/DownloadApk.ashx?id=8";
        final NotyManager no=new NotyManager(getApplicationContext());
     
        
        Button bt=(Button)findViewById(R.id.button1);
        bt.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				
				d=new DownloadByAppacheHttp(getApplicationContext(), no);
		   //     Download d=new Download(getApplicationContext(), no,new Random().nextInt());
		        d.execute(link,Environment.getExternalStorageDirectory()+"/file.apk");
		        Toast.makeText(getApplicationContext(), "Start", Toast.LENGTH_LONG).show();
			}
			
		});
        
        //pause
        Button bt2=(Button)findViewById(R.id.button2);
        bt2.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				d.cancel();
				//d.clearNotify();
				 Toast.makeText(getApplicationContext(), "pause", Toast.LENGTH_LONG).show();
			}
		});
        
        //resume
        Button bt3=(Button)findViewById(R.id.button3);
        bt3.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				   d=new DownloadByAppacheHttp(getApplicationContext(), no);
				  d.execute(link,Environment.getExternalStorageDirectory()+"/file.apk");
				  Toast.makeText(getApplicationContext(), "resume", Toast.LENGTH_LONG).show();
			}
		});
    }

}
